'use strict';

const Controller = require('egg').Controller;

class DoLoginController extends Controller {
  async index() {
    const { ctx } = this;
    var {administrator , pwd} = ctx.request.body
    var db = this.app.mongodb
    var res =await db.collection("administrator").find({administrator , pwd}).toArray();
    if (res.length) {
      ctx.body = "<script>alert('验证成功，恭喜登录');location.href='/home'</script>"
      ctx.cookies.set("login","success")
    }else{
      ctx.body = "<script>alert('用户名或密码错误');location.href='/login'</script>"
    }
  }
}

module.exports = DoLoginController;
